package com.xiaoyung.easyisapisdk.common.util;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class ReflectUtils {
	
	// 获取返回类型的实际类型参数 List<PageData> => PageData
	public static Class<?> getReturnTypeGenericArgument(Method method) {
		Type returnType = method.getGenericReturnType();
		if (returnType instanceof ParameterizedType) {
			ParameterizedType type = (ParameterizedType) returnType;
			Type[] typeArguments = type.getActualTypeArguments();
			return (Class<?>) typeArguments[0];
			/*for (Type typeArgument : typeArguments) {
				System.out.println("Type argument: " + typeArgument); // 应该输出 class java.lang.String
			}*/
		}
		return null;
	}
	
}
